package com.shuorikeji.huohuo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.shuorikeji.huohuo.R;
import com.shuorikeji.huohuo.callback.ClickCallBack;
import com.shuorikeji.huohuo.common.Constant;
import com.shuorikeji.huohuo.utils.BusinessUtils;
import com.shuorikeji.huohuo.view.ZdyMhImageView;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class MhViewPagerAdapter extends RecyclerView.Adapter<MhViewPagerAdapter.PagerViewHolder> {
    private List<String> mData = new ArrayList<>();
    private Context mContext;
    private ClickCallBack callBack;

    public MhViewPagerAdapter(Context context, ClickCallBack callBack) {
        mContext = context;
        this.callBack = callBack;
    }

    @NonNull
    @Override
    public PagerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.mh_item_layout, parent, false);
        return new PagerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PagerViewHolder holder, int position) {
        BusinessUtils.setLoadImg(mContext, Constant.IMG_OSS_BASE_URL + "/" + mData.get(position), holder.ivMh);
        holder.ivMh.setOnClickListener(view -> {
            callBack.onClick(1, null);
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public void setData(List<String> data) {
        if (mData != null) {
            mData.clear();
            mData.addAll(data);
            notifyDataSetChanged();
        }
    }

    class PagerViewHolder extends RecyclerView.ViewHolder {
        ZdyMhImageView ivMh;

        public PagerViewHolder(View itemView) {
            super(itemView);
            ivMh = itemView.findViewById(R.id.iv_mh);
        }
    }
}
